import request from '@/utils/request'

export function getTable(params) {
  return request({
    url: 'api/inspectPlan',
    method: 'GET',
    params
  })
}
export function add(data) {
  return request({
    url: 'api/inspectPlan',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: `api/inspectPlan/${ids[0]}`,
    method: 'delete'
    // data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/inspectPlan',
    method: 'put',
    data
  })
}

export function queryInspectProject(params) {
  return request({
    url: '/api/project/queryInspectProject',
    method: 'get',
    params
  })
}
export function querySubListByProjId(params) {
  return request({
    url: '/api/projectSub/querySubListByProjId',
    method: 'get',
    params
  })
}
export function queryRoleRelevanceUsers(params) {
  return request({
    url: '/api/roles/queryRoleRelevanceUsers',
    method: 'get',
    params
  })
}
export function inspectPlanResultScoreExport(params) {
  return request({
    url: '/api/inspectPlanResultScore/export',
    method: 'post',
    params,
    responseType: 'blob'
  })
}
export function inspectPlanTurnover(id, status) {
  return request({
    url: `/api/inspectPlan/turnover/${id}/${status}`,
    method: 'post'
  })
}
export function queryProjInspectCompany(params) {
  return request({
    url: `/api/inspectPlan/queryProjInspectCompany`,
    method: 'get',
    params
  })
}
export function checkInspectCompanyEdit(params) {
  return request({
    url: `/api/inspectPlan/checkInspectCompanyEdit`,
    method: 'get',
    params
  })
}
export function getDownloadName(data) {
  return request({
    url: `/api/inspectPlan/buildDownloadName`,
    method: 'post',
    data
  })
}
export function downloadPost(data, filename) {
  return request({
    url: '/api/inspectPlan/download',
    method: 'post',
    responseType: 'blob',
    data
  }).then(response => {
    const url = window.URL.createObjectURL(new Blob([response]))
    const link = document.createElement('a')
    link.style.display = 'none'
    link.href = url
    const decodedString = filename
    link.setAttribute('download', decodedString)
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
  })
}

export function getDetail(params) {
  return request({
    url: '/api/inspectPlan/getDetail',
    method: 'get',
    params
  })
}
export function querySameMonthInspectInfo(params) {
  return request({
    url: 'api/inspectPlan/querySameMonthInspectInfo',
    method: 'get',
    params
  })
}
export function checkSameMonthInspectEdit(params) {
  return request({
    url: '/api/inspectPlan/checkSameMonthInspectEdit',
    method: 'get',
    params
  })
}
export function getSendEmailList(params) {
  return request({
    url: '/api/inspectPlan/getSendEmailList',
    method: 'get',
    params
  })
}
export function sendInspectPlanEmail(data) {
  return request({
    url: '/api/inspectPlan/sendInspectPlanEmail',
    method: 'post',
    data
  })
}

// 查询评审结果
export function queryResultScoreForPlan(params) {
  return request({
    url: 'api/inspectPlanResultScore/queryResultScoreForPlan',
    method: 'get',
    params
  })
}
// 查询评审结果
export function queryResultScoreForPlanV2(params) {
  return request({
    url: 'api/inspectPlanStatisticData/queryInspectPlanDetail',
    method: 'get',
    params
  })
}

export function sendCheckNotificationEmail(data) {
  return request({
    url: '/api/inspectPlan/sendCheckNotificationEmail',
    method: 'post',
    data
  })
}
export function selectEmailLogList(data) {
  return request({
    url: '/api/inspectPlan/selectEmailLogList',
    method: 'post',
    data
  })
}
export function sendScoreResultEmail(data) {
  return request({
    url: '/api/inspectPlan/sendScoreResultEmail',
    method: 'post',
    data
  })
}

export function exportInspectPlanStatisticsData(params) {
  return request({
    url: '/api/inspectPlanStatisticData/exportInspectPlanStatisticsData',
    method: 'get',
    responseType: 'blob',
    params
  })
}

// 获取可得的年份
export function queryAvailableYears() {
  return request({
    url: '/api/inspectPlan/queryAllReviewYear',
    method: 'get'
  })
}
export default { add, edit, del }
